home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 001-100 / 001-025 / 003 / xlisp / xlbind.c < prev    next >
C/C++ Source or Header  |  1995-03-17  |  2KB  |  70 lines

  1. /* xlbind - xlisp symbol binding routines */
  2.  
  3. #include "xlisp.h"
  4.  
  5. /* external variables */
  6. extern NODE *xlenv,*xlnewenv;
  7.  
  8. /* xlsbind - bind a value to a symbol sequentially */
  9. xlsbind(sym,val)
  10.   NODE *sym,*val;
  11. {
  12.     NODE *ptr;
  13.  
  14.     /* create a new environment list entry */
  15.     ptr = newnode(LIST);
  16.     rplacd(ptr,xlenv);
  17.     xlenv = ptr;
  18.  
  19.     /* create a new variable binding */
  20.     rplaca(ptr,newnode(LIST));
  21.     rplaca(car(ptr),sym);
  22.     rplacd(car(ptr),sym->n_symvalue);
  23.     sym->n_symvalue = val;
  24. }
  25.  
  26. /* xlbind - bind a value to a symbol in parallel */
  27. xlbind(sym,val)
  28.   NODE *sym,*val;
  29. {
  30.     NODE *ptr;
  31.  
  32.     /* create a new environment list entry */
  33.     ptr = newnode(LIST);
  34.     rplacd(ptr,xlnewenv);
  35.     xlnewenv = ptr;
  36.  
  37.     /* create a new variable binding */
  38.     rplaca(ptr,newnode(LIST));
  39.     rplaca(car(ptr),sym);
  40.     rplacd(car(ptr),val);
  41. }
  42.  
  43. /* xlfixbindings - make a new set of bindings visible */
  44. xlfixbindings()
  45. {
  46.     NODE *eptr,*bnd,*sym,*oldvalue;
  47.  
  48.     /* fix the bound value of each symbol in the environment chain */
  49.     for (eptr = xlnewenv; eptr != xlenv; eptr = cdr(eptr)) {
  50.     bnd = car(eptr);
  51.     sym = car(bnd);
  52.     oldvalue = sym->n_symvalue;
  53.     sym->n_symvalue = cdr(bnd);
  54.     rplacd(bnd,oldvalue);
  55.     }
  56.     xlenv = xlnewenv;
  57. }
  58.  
  59. /* xlunbind - unbind symbols bound in this environment */
  60. xlunbind(env)
  61.   NODE *env;
  62. {
  63.     NODE *bnd;
  64.  
  65.     /* unbind each symbol in the environment chain */
  66.     for (; xlenv != env; xlenv = cdr(xlenv))
  67.     if (bnd = car(xlenv))
  68.         car(bnd)->n_symvalue = cdr(bnd);
  69. }
  70.